package com.feather.common.converter.simple.namematch;

import com.feather.common.converter.ArrayIndex;
import com.feather.common.converter.NameMatch;

/**
 * @author flogyin
 */
public class NameMatch__Array_CaseMatch implements NameMatch {
	private static NameMatch__Array_CaseMatch	nameMatch	= new NameMatch__Array_CaseMatch();

	public static NameMatch instance() {
		return nameMatch;
	}

	@Override
	public int match(String prefix, String key, String field, ArrayIndex arrayindex) {
		if (!key.startsWith(field + arrayindex.start)) {
			return NOT_MATCH;
		}
		if (key.charAt(key.length() - 1) != arrayindex.end) {
			return NOT_MATCH;
		}

		String indexStr = key.substring(field.length() + 1, key.length() - 1);
		try {
			return Integer.parseInt(indexStr);
		} catch (Exception ex) {
			return NOT_MATCH;
		}
	}
}
